<!doctype html>
<html>
<!--
Copyright 2011 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.jsaction.jsprops</title>
<script src="../base.js"></script>
<script>
goog.require('goog.jsaction.jsprops');
goog.require('goog.testing.jsunit');
</script>
<script>


function testGet() {
  var elem = document.createElement('div');
  elem.setAttribute('jsprops', '{gna:"fu", seven:7}');

  assertEquals('fu', goog.jsaction.jsprops.get(elem, 'gna'));
  assertEquals(7, goog.jsaction.jsprops.get(elem, 'seven'));
  assertEquals(undefined, goog.jsaction.jsprops.get(elem, 'undefined'));
}


function testGetNoAttribute() {
  var elem = document.createElement('div');
  assertEquals(undefined, goog.jsaction.jsprops.get(elem, 'undefined'));
}


function testSet() {
  var elem = document.createElement('div');
  elem.setAttribute('jsprops', '{gna: "fu"}');

  assertEquals('fu', goog.jsaction.jsprops.get(elem, 'gna'));
  goog.jsaction.jsprops.set(elem, 'gna', 'more fu');
  assertEquals('more fu', goog.jsaction.jsprops.get(elem, 'gna'));
}


function testSetNoAttribute() {
  var elem = document.createElement('div');

  assertEquals(undefined, goog.jsaction.jsprops.get(elem, 'gna'));
  goog.jsaction.jsprops.set(elem, 'gna', 'more fu');
  assertEquals('more fu', goog.jsaction.jsprops.get(elem, 'gna'));
}


function testUpdateAttribute() {
  var elem = document.createElement('div');
  elem.setAttribute('jsprops', '{"num":3}');

  assertEquals(3, goog.jsaction.jsprops.get(elem, 'num'));

  goog.jsaction.jsprops.set(elem, 'num', 4, false);
  assertEquals(4, goog.jsaction.jsprops.get(elem, 'num'));
  assertEquals('{"num":3}', elem.getAttribute('jsprops'));

  goog.jsaction.jsprops.updateAttribute(elem);
  assertEquals('{"num":4}', elem.getAttribute('jsprops'));

  goog.jsaction.jsprops.set(elem, 'num', 5, true);
  assertEquals(5, goog.jsaction.jsprops.get(elem, 'num'));
  assertEquals('{"num":5}', elem.getAttribute('jsprops'));
}


</script>
</head>
</html>
